<?php 	
	include_once("connect.php");	
	include_once("post_model.php");
	include_once("utility.php");
	include_once("tag_model.php");
	session_start();
	mysql_select_db("progin_171_13509047",$con);		
?>


<?php 
	//TODO : like belom
	
	$post_model = new Post_Model();	
	$tag_model = new Tag_Model();
	$favorite_posts_res = $post_model->getPostOrderedLimited('like_count',3);	
	$most_commented_res = $post_model->getPostOrderedLimited('post.comment_count',3);
	$uid = (isset($_SESSION["userid"]))? $_SESSION["userid"]:"";
?>

<?php 
	include_once("header.php"); 
?>
	
	<!-- Body -->
<div id="bodycontent">
	<div class="contentcontainer">

	<div class="title-text">
	  <h1>Most Favorite Content</h1>
	</div>		

	<div class="contentboxh">
		<?php while($fav_row = mysql_fetch_array($favorite_posts_res)) : ?>		
		  <div class="home-box">
			<div><h3><a href="content.php?id=<?php echo $fav_row["post_id"] ?>"><?php echo $fav_row["title"] ?></a></h3></div>
			<?php if($fav_row["post_type"]=="image") : ?>
			<div>
				<a href="content.php?id=<?php echo $fav_row["post_id"] ?>">
					<img src="upload/<?php echo $fav_row["content"] ?>" class="thumbnailh" alt="Konten 1"/>
				</a>
			</div>
			<?php elseif($fav_row["post_type"]=="link") :  
				$str = explode("\n", $fav_row["content"]);
				$link = $str[0];
				$desc = $str[1];
			?>
			<div>
				link : <a href="<?php echo $link; ?>"><?php echo $link; ?></a><br />
				description : <?php echo $desc; ?>
			</div>
			<?php elseif($fav_row["post_type"]=="video") : 
				$tube_id = substr($fav_row['content'],31, strlen($fav_row['content']) + 1);
			?>
			<div>
				<object type="application/x-shockwave-flash" style="width:560px; height:315px;" data="http://www.youtube.com/v/<?php echo $tube_id; ?>?version=3">
				<param name="movie" value="http://www.youtube.com/v/'.$tube_id.'?version=3" />
				<param name="allowFullScreen" value="true" />
				<param name="allowscriptaccess" value="always" />
				</object>
			</div>
			<?php endif; ?>
			<div class="buttons"><a onclick=doLikeOp("like\@<?php echo $fav_row["post_id"]?>","class")><img src=like.png width=20 height=20 alt=like></a><a onclick=doLikeOp("dislike\@<?php echo $fav_row["post_id"]?>","class")><img src=dislike.png width=20 height=20 alt=dislike></a></div>
			<?php $post_model->printLikeWithClass($fav_row["like_count"],$uid,$fav_row["post_id"])?>
			<div><small><i><?php echo $fav_row["comment_count"] ?> peoples commented this post</i></small></div>
			<p><small><i>Uploaded by <a href="profile.php?id=<?php echo $fav_row["poster_id"]; ?>"><?php echo $fav_row["username"]; ?></a> <?php echo Utility::getDeltaTimeString(new DateTime($fav_row['datetime'], new DateTimeZone('Asia/Jakarta')), new DateTime(null, new DateTimeZone('Asia/Jakarta'))); ?> </i></small></p>
			<?php 
				$tag_res = $tag_model->getTagInfo($fav_row["post_id"]);
				
				$tag_row = mysql_fetch_array($tag_res);					
				$tag_string = $tag_row["type"];
				while($tag_row = mysql_fetch_array($tag_res)) {
					$tag_string.=",";
				}
				echo "<p>".$tag_string."</p>";
			?>
		  </div>		
		<?php endwhile; ?>
	</div>	

	<!-- Bagian Most Commented -->

	<div class="title-text">
		<h1>Most Commented Content</h1>
	</div>

	<div class="contentboxh">
		<?php while($comm_row = mysql_fetch_array($most_commented_res)) : ?>		
		  <div class="home-box">
			<div><h3><a href="content.php?id=<?php echo $comm_row["post_id"] ?>"><?php echo $comm_row["title"] ?></a></h3></div>
			<?php if($comm_row["post_type"]=="image") : ?>
			<div>
				<a href="content.php?id=<?php echo $comm_row["post_id"] ?>">
					<img src="upload/<?php echo $comm_row["content"] ?>" class="thumbnailh" alt="Konten 1"/>
				</a>
			</div>
			<?php elseif($comm_row["post_type"]=="link") :  
				$str = explode("\n", $comm_row["content"]);
				$link = $str[0];
				$desc = $str[1];
			?>
			<div>
				link : <a href="<?php echo $link; ?>"><?php echo $link; ?></a><br />
				description : <?php echo $desc; ?>
			</div>
			<?php elseif($comm_row["post_type"]=="video") : 
				$tube_id = substr($comm_row['content'],31, strlen($comm_row['content']) + 1);
			?>
			<div>
				<object type="application/x-shockwave-flash" style="width:560px; height:315px;" data="http://www.youtube.com/v/<?php echo $tube_id; ?>?version=3">
				<param name="movie" value="http://www.youtube.com/v/'.$tube_id.'?version=3" />
				<param name="allowFullScreen" value="true" />
				<param name="allowscriptaccess" value="always" />
				</object>
			</div>
			<?php endif; ?>
			<div class="buttons"><a onclick=doLikeOp("like\@<?php echo $comm_row["post_id"]?>","class")><img src=like.png width=20 height=20 alt=like></a><a onclick=doLikeOp("dislike\@<?php echo $comm_row["post_id"]?>","class")><img src=dislike.png width=20 height=20 alt=dislike></a></div>
			<?php $post_model->printLikeWithClass($comm_row["like_count"],$uid,$comm_row["post_id"])?>
			<div><small><i><?php echo $comm_row["post_comment_count"] ?> peoples commented this post</i></small></div>
			<p><small><i>Uploaded by <a href="profile.php?id=<?php echo $poster_id; ?>"><?php echo $comm_row["username"]; ?></a> <?php echo Utility::getDeltaTimeString(new DateTime($comm_row['datetime'], new DateTimeZone('Asia/Jakarta')), new DateTime(null, new DateTimeZone('Asia/Jakarta'))); ?> </i></small></p>
			<?php 
				$tag_res = $tag_model->getTagInfo($comm_row["post_id"]);
				
				$tag_row = mysql_fetch_array($tag_res);					
				$tag_string = $tag_row["type"];
				while($tag_row = mysql_fetch_array($tag_res)) {
					$tag_string.=",";
				}
				echo "<p>".$tag_string."</p>";
			?>
		  </div>		
		<?php endwhile; ?>
	</div>			

	</div>
</div>

<?php include_once("footer.php") ?>